package mysql

import (
	"gorm.io/gorm"
	"novel-kit/novelrpc/novelrpc"
)

type BookDesk struct {
	gorm.Model
	UserId  int `gorm:"type:int;not null;comment:'用户id'"`
	NovelId int `gorm:"type:int;not null;comment:'小说id'"`
}

func (d *BookDesk) BookdeskAdd(db *gorm.DB) error {
	return db.Create(d).Error
}

func FindBookDeskByUserId(db *gorm.DB, id int64) []*novelrpc.BookDeskShow {
	var findBookDesk []*novelrpc.BookDeskShow
	db.Model(&BookDesk{}).Select("novels.id as novel_id,novel_type,novel_name,content,novel_image").
		Joins("LEFT JOIN users ON book_desks.user_id=users.id").
		Joins("LEFT JOIN novels ON book_desks.novel_id=novels.id").
		Where("users.id=?", id).Find(&findBookDesk)
	return findBookDesk
}
